package com.normalsys.live.dao;

import com.normalsys.live.base.mapper.MsMapper;
import com.normalsys.live.entity.SmsCode;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface SmsCodeDAO extends MsMapper<SmsCode> {

    /**
     * 查询验证码是否匹配
     * @param phone
     * @param code
     * @param codeExpireTime
     * @return
     */
    @Select("select * from tb_sms_code where phone=#{phone} and code=#{code} and create_time <= #{codeExpireTime} and status = 1 limit 1")
    @ResultType(SmsCode.class)
    SmsCode checkSmsCode(@Param("phone") String phone, @Param("code") String code, @Param("codeExpireTime") String codeExpireTime);

    /**
     * 查询手机号一分钟之内是否发过验证码
     * @param phone
     * @return
     */
    @Select("select * from tb_sms_code where phone=#{phone} and create_time > #{now} ")
    @ResultType(SmsCode.class)
    SmsCode getCodeByPhoneOneMinute(@Param("phone") String phone, @Param("now") String now);
}
